package com.ask.chatApis;

import com.ask.entity.ChatRequest;


import com.ask.entity.Message;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;

public class ChatClient {
    private static final String DP_URL = "https://api.deepseek.com/chat/completions";
    private static final String V3_URL = "https://api.gpt.ge/v1/chat/completions";
    private static final String DP_KEY = "Bearer sk-21a9efacd4cc4f8886a20dccae0e97ae";
    private static final String V3_KEY = "Bearer sk-fwQGVRA2oqYRUWhR51F88a5b43C54aCa9d2eEd3b229c8cE9";
    private static final String MODEL_ID = "deepseek-chat";

    public static void main(String[] args)  {
        //deepSeek();
        v3();
    }

    private static void deepSeek() {
        // 创建 RestTemplate 实例
        RestTemplate restTemplate = new RestTemplate();


        // 创建请求体
        ChatRequest chatRequest = new ChatRequest();
        chatRequest.setModel(MODEL_ID);
        chatRequest.setMessages(Collections.singletonList(new Message("user", "给出冒泡排序的代码实现")));
        chatRequest.setMax_tokens(1688);
        chatRequest.setTemperature(0.5);
        chatRequest.setStream(false);

        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", DP_KEY); // 替换为你的 API Key

        // 创建 HttpEntity
        HttpEntity<ChatRequest> request = new HttpEntity<>(chatRequest, headers);

        // 发送 POST 请求
        ResponseEntity<String> response = restTemplate.postForEntity(DP_URL, request, String.class);

        // 输出响应
        System.out.println("Status Code: " + response.getStatusCode());
        System.out.println("Response Body: " + response.getBody());
    }

    public static void v3() {
        // 创建 RestTemplate 实例
        RestTemplate restTemplate = new RestTemplate();


        // 创建请求体
        ChatRequest chatRequest = new ChatRequest();
        chatRequest.setModel("gpt-4o");
        chatRequest.setMessages(Collections.singletonList(new Message("user", "给出冒泡排序的代码实现")));
        chatRequest.setMax_tokens(1688);
        chatRequest.setTemperature(0.5);
        chatRequest.setStream(false);

        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", V3_KEY); // 替换为你的 API Key

        // 创建 HttpEntity
        HttpEntity<ChatRequest> request = new HttpEntity<>(chatRequest, headers);

        // 发送 POST 请求
        ResponseEntity<String> response = restTemplate.postForEntity(V3_URL, request, String.class);

        // 输出响应
        System.out.println("Status Code: " + response.getStatusCode());
        System.out.println("Response Body: " + response.getBody());
    }
}